import {Button, Card, Form, Input, message} from 'antd';
import {login} from "../../Request/api";
const onFinish = (values) => {
   login(values).then(res => {
       console.log(res)
       if (res.data === true) {
           message.success("登陆成功")
           localStorage.setItem("token", values.email)
           window.location.href = "/home"
       } else {
           message.error("账号或密码错误")
       }
   })
};
const onFinishFailed = (errorInfo) => {
    console.log('Failed:', errorInfo);
};
const App = () => {
    message.info("请登录")
    return(
        <Card title={"用户登陆"}>
            <Form
                name="basic"
                initialValues={{
                    remember: true,
                }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item
                    label="邮箱"
                    name="email"
                    rules={[
                        {
                            required: true,
                            message: '请输入邮箱!',
                        },
                        {
                            type: "email",
                            message: '请输入正确的邮箱！',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[
                        {
                            required: true,
                            message: 'Please input your password!',
                        },
                    ]}
                >
                    <Input.Password />
                </Form.Item>
                <Form.Item
                >
                    <Button type="primary" htmlType="submit">
                        登陆
                    </Button>
                </Form.Item>
            </Form>
        </Card>
    );
}
export default App;